import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import statsmodels.api as sm

# 加载数据
gov_funding = pd.read_csv('C:\\Users\\lizhiyi.i\\Desktop\\毕设\\gov_funding.csv')
innovation = pd.read_csv('C:\\Users\\lizhiyi.i\\Desktop\\毕设\\innovation.csv')
# 合并数据
data = pd.merge(gov_funding, innovation, on='Year')
# 计算相关系数
correlation = data[['Funding', 'Patent', 'Project']].corr()
# 可视化数据
plt.figure(figsize=(8, 6))
sns.heatmap(correlation, annot=True, cmap='coolwarm')
plt.title('Correlation Matrix')
plt.show()

# 加载数据
gov_funding = pd.read_csv('C:\\Users\\lizhiyi.i\\Desktop\\毕设\\gov_funding.csv')
innovation = pd.read_csv('C:\\Users\\lizhiyi.i\\Desktop\\毕设\\innovation.csv')
# 构建线性回归模型1：政府科技经费支出与专利申请数量之间的关系
data_patent = pd.merge(gov_funding, innovation[['Year', 'Patent']], on='Year')
X_patent = data_patent[['Funding']]
Y_patent = data_patent[['Patent']]
X_patent = sm.add_constant(X_patent)     # 增加常数项
model_patent = sm.OLS(Y_patent, X_patent).fit()
print("模型1摘要信息：\n", model_patent.summary())
# 构建线性回归模型2：政府科技经费支出与项目申报数量之间的关系
data_proj = pd.merge(gov_funding, innovation[['Year', 'Project']], on='Year')
X_proj = data_proj[['Funding']]
Y_proj = data_proj[['Project']]
X_proj = sm.add_constant(X_proj)     # 增加常数项
model_proj = sm.OLS(Y_proj, X_proj).fit()
print("模型2摘要信息：\n", model_proj.summary())